package author9_1_2_1;

public class Book extends Object {
	private String name;
	private Author author;
	private double price;
	private int qty = 0;

	public Book(String name, Author author, double price) {
		super();
		this.name = name;
		this.author = author;
		this.price = price;
	}

	public Book(String name, Author author, double price, int qty) {
		super();
		this.name = name;
		this.author = author;
		this.price = price;
		this.qty = qty;
	}

	public String getName() {
		return name;
	}

	public Author getAuthor() {
		return author;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	public String getAuthorName() {
		return this.getAuthor().getName();
	}

	public String getAuthorEmail() {
		return this.getAuthor().getEmail();
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return name.hashCode() + author.hashCode() + Double.hashCode(price) + qty;
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(!(obj instanceof Book))
			return false;
		Book book = (Book) obj;
		return this.name == book.name && this.author == book.author && this.price == book.price && this.qty == book.qty;
	}

	@Override
	public String toString() {
		return "Book [name=" + name + ", author=" + author + ", price=" + price + ", qty=" + qty + "]";
	}

}
